﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using hzGis.utils;
using System.IO;
using hzGis.model;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using hzGis.config;
using hzGis.service.impl.ydhy;
using hzGis.service.impl;

namespace hzGis
{
    public partial class DlHyWin : Form
    {
        YdhyOffice ydhyOffice;
        YdhyService ydhyService;
        public DlHyWin()
        {
            InitializeComponent();
            ydhyOffice = new YdhyOffice();
            ydhyService = new YdhyService();
        }

        private void DlHyWin_Load(object sender, EventArgs e)
        {

        }

        private void sjclBtn_Click(object sender, EventArgs e)
        {
            string startTime = System.DateTime.Now.ToString("F");
            ISpatialReference prj4526 = PrjUtils.createSpatialReference(SysConfig.PRJ_FILE4526);
            string gdbPath = @"D:\data\ydbp\test\result\rs.gdb";
            FeatureClassInfo targetFeatureClassInfo = null;
            if (!Directory.Exists(gdbPath))
            {
                targetFeatureClassInfo = GdbUtils.CreateFileGdbWorkspace(gdbPath);
            }
            else
            {
                targetFeatureClassInfo = FeatureClassUtils.OpenGDBWorkspace(gdbPath, null);
            }
            // 将对应的数据导入到指定的gdb中
            List<Dictionary<string, object>> datas = ydhyOffice.buildAnalysisDatas();
            for (int i = 0; i < datas.Count; i++)
            {
                Dictionary<string, object> data = datas[i];
                FeatureClassInfo sourceFeatureClassInfo = FeatureClassUtils.openFeatureClass(data["path"].ToString());
                GdbUtils.shpImportGdb(sourceFeatureClassInfo.fc, data["fields"] as List<FieldConn>, prj4526, targetFeatureClassInfo.wp, "tlb" + data["year"]);
                MemoryHelper.ReleaseFeatureClass(sourceFeatureClassInfo.fc);
            }
            // 将报批红线的数据与本地shp叠加生成放到gdb中
            List<Dictionary<string, string>> paths = ydhyOffice.buildDataPaths();
            ydhyService.ydhyPro(paths, targetFeatureClassInfo.wp, gdbPath, startTime);
        }
    }
}
